package free.akerigan.yafb2lib.model;

import java.util.ArrayList;

public class AuthorModel {

    String id = null;
    String firstName = null;
    String middleName = null;
    String lastName = null;
    
    ArrayList<Integer> books;
    
    public String getId() {
	return id;
    }

    public void setId(String id) {
	this.id = id;
    }

    public String getFirstName() {
	return firstName;
    }

    public void setFirstName(String firstName) {
	this.firstName = firstName.trim();
    }

    public String getMiddleName() {
	return middleName;
    }

    public void setMiddleName(String middleName) {
	this.middleName = middleName.trim();
    }

    public String getLastName() {
	return lastName;
    }

    public void setLastName(String lastName) {
	this.lastName = lastName.trim();
    }

    public String getFullName() {
	StringBuilder result = new StringBuilder();
	if (firstName != null) {
	    result.append(firstName + " ");
	}
	if (middleName != null) {
	    result.append(middleName + " ");
	}
	if (lastName != null) {
	    result.append(lastName + " ");
	}
	return result.toString().trim();
    }
    
    public void addBook(int bookId) {
	if (books == null) {
	    books = new ArrayList<Integer>();
	}
	books.add(bookId);
    }
    
    public int getBooksCount() {
	if (books == null) {
	    return 0;
	} else {
	    return books.size();
	}
    }
    
    public int getBookId(int index) {
	if (books == null || index < 0 || index > books.size()-1) {
	    return -1;
	} else {
	    return books.get(index);
	}
    }
    

}
